package yh.plugins.workflow.system;

import java.sql.Connection;
import java.sql.Statement;
import java.util.Map;

import yh.core.funcs.workflow.util.YHIWFHookPlugin;

public class YHAssetRepair implements YHIWFHookPlugin{

	  /* 
	   * 审核通过则修改状态
	   * (non-Javadoc)
	   *  //var arrayState=["未知","未使用","","已领用","报修中","报废","报废中","返库","返库中"];
	   * @see yh.core.funcs.workflow.util.YHIWFHookPlugin#execute(java.sql.Connection, int, java.util.Map, java.util.Map, boolean)
	   */
	   @Override
	  public String execute(Connection dbConn, int runId, Map arrayHandler, Map formData, boolean agree) throws Exception {
		 //var arrayState=["未知","未使用","","已领用","报修中","报废","报废中","返库","返库中"]; 	
		
		   ////{"KEY":"业务主键","NETIZEN_NAME":"业务网民名称","CONTENT":"业务提交内容","REMARK":"业务提交描述","SUBMIT_DATE":"业务提交日期","FTYPE":"业务状态"}
		   //可以得到审批表单中的值：
//	     String NETIZEN_NAME =(String)arrayHandler.get("NETIZEN_NAME");
//         String CONTENT=(String)arrayHandler.get("CONTENT");
//         String REMARK=(String)arrayHandler.get("REMARK");
//         String SUBMIT_DATE=(String)arrayHandler.get("SUBMIT_DATE");
//         String remove_reason=(String)arrayHandler.get("REASON");
    //可以获取映射内容进行其他操作，此处忽略，只对状态更新
		   String isAgree=formData.get("负责人审批").toString();
			String seqId = (String) arrayHandler.get("KEY");//管理表id
			Statement st  = null;
			
			try{
				st = dbConn.createStatement();
				//更新报修状态为已领用
				String sql ="";
				if(isAgree.equals("同意")){
				 sql = "update OA_ASSET_INFO set USE_STATE = '3',SQ_STATUS='0' where seq_id='"+seqId+"'";
				}else{
				 sql = "update OA_ASSET_INFO set USE_STATE = '3',SQ_STATUS = '0' where seq_id='"+seqId+"'";	
				}
				
				st.executeUpdate(sql);
			}
			catch (Exception e) {
				dbConn.rollback();
				throw e;
			}
			return null;
	  }
	}
